##  Nazi trials paper
##  Code to plot TABLE 2 and FIGURES 1-9 in the SI
##

rm(list = ls(all.names = TRUE))
library(Hmisc)

#setwd("~/Dropbox/Current projects/Nazi trials/analysis")
load("Nazi trials replication data.RData")
file.info("Nazi trials replication data.RData")$mtime

load("Nazi trials replication data population statistics.RData")
file.info("Nazi trials replication data population statistics.RData")



##  Table of crime categorization (TABLE 2 in the article)
tab1 <- matrix(NA,10,4)
colnames(tab1) <- c("Category","n", "%", "% convicted") 
tab1[,1] <- colnames(cases.temp)[3:12]


m <- 1
for(m in 1:nrow(tab1))	{

	tab1[m,2] <- sum(cases.temp[tab1[m,1]])
	tab1[m,3] <- round(sum(cases.temp[tab1[m,1]]) / nrow(cases.temp),2)*100
	tab1[m,4] <- round(mean(cases.temp$convicted[cases.temp[tab1[m,1]] == 1]),2)*100

						}

tab1[3,1] <- "Crimes committed in final weeks of war"
tab1[4,1] <- "Extermination by {\\it Einsatzgruppen}"
tab1[5,1] <- "Extermination in camps"
tab1[6,1] <- "Extermination (other)"
tab1[7,1] <- "Judicial crimes"
tab1[8,1] <- "Crimes committed during NS detainment"
tab1[9,1] <- "Other NS crimes"
tab1[10,1] <- "War crimes"

tab1 <- tab1[order(tab1[,1]),]

tab1
latex(tab1, file = "")



##  distribution of prison sentence lengths (FIGURE 9 in the SI)
#pdf(file = "plots/sentence_length.pdf")
hist(cases.temp$Months2, main = "", xlab = "Prison sentence length (months)", xlim = c(0,200),20)
dev.off()

rm(m,tab1)



##  Composition of district courts (FIGURE 1 in the SI)
#pdf(file = "plots/overtime1.pdf")
par(mfcol = c(2,1), mar = c(4, 4, 2, 1))

boxplot(Nazi.temp.20[,3:15], xlab = "Year", ylab = "% judges who were appointed in 1933-45",
cex.axis = .8, cex.lab = .8, ylim = c(0,.7))

boxplot(Nazi.temp.24[,3:15], xlab = "Year", ylab = "avg. share of judges' legal training in 1933-45",
cex.axis = .8, cex.lab = .8, ylim = c(0,.7))

dev.off()



##  Composition of district courts (FIGURE 2 in the SI)
#pdf(file = "plots/overtime2.pdf")
par(mfcol = c(2,2), mar = c(4, 4, 2, 1))


boxplot(Nazi.temp.19[,3:15], xlab = "Year", ylab = "% judges who were appointed before 1933",
cex.axis = .8, cex.lab = .8, ylim = c(0,1))

boxplot(Nazi.temp.23[,3:15], xlab = "Year", ylab = "avg. share of judges' legal training before 1933",
cex.axis = .8, cex.lab = .8, ylim = c(0,1))


##  residual category
boxplot(1-Nazi.temp.19[,3:15]-Nazi.temp.20[,3:15], xlab = "Year",
ylab = "% judges who were appointed after 1945",
cex.axis = .8, cex.lab = .8, ylim = c(0,1))

boxplot(1-Nazi.temp.23[,3:15]-Nazi.temp.24[,3:15], xlab = "Year",
ylab = "avg. share of judges' legal training after 1945",
cex.axis = .8, cex.lab = .8, ylim = c(0,1))

dev.off()



##  within court variation over time
##  reorder cities alphabetically
Nazi.temp.19 <- Nazi.temp.19[order(Nazi.temp.19$city, decreasing = TRUE),]
Nazi.temp.20 <- Nazi.temp.20[order(Nazi.temp.20$city, decreasing = TRUE),]
Nazi.temp.23  <- Nazi.temp.23[order(Nazi.temp.23$city, decreasing = TRUE),]
Nazi.temp.24  <- Nazi.temp.24[order(Nazi.temp.24$city, decreasing = TRUE),]


##  FIGURE 3 in the SI
#pdf(file = "plots/appointed_pre_33.pdf")
par(mar = c(3, 6, 1, 4))	#c(bottom, left, top, right)

boxplot(t(Nazi.temp.19[,3:15]), ylab = "", cex.axis = 0.4, cex.lab = .8, las = 2,
names = paste0("LG ",Nazi.temp.19[,1]), horizontal = TRUE, outline = FALSE, ylim = c(0,1))

mtext(side = 1, "% judges who were appointed before 1933", line = 1.5, cex = .8)
dev.off()



##  FIGURE 4 in the SI
#pdf(file = "plots/appointed_33_45.pdf")
par(mar = c(3, 6, 1, 4))	#c(bottom, left, top, right)

boxplot(t(Nazi.temp.20[,3:15]), ylab = "", cex.axis = 0.4, cex.lab = .8, las = 2,
names = paste0("LG ",Nazi.temp.20[,1]), horizontal = TRUE, outline = FALSE, ylim = c(0,1))

mtext(side = 1, "% judges who were appointed between 1933 and 1945", line = 1.5, cex = .8)
dev.off()



##  FIGURE 5 in the SI
#pdf(file = "plots/appointed_post_45.pdf")
par(mar = c(3, 6, 1, 4))	#c(bottom, left, top, right)

boxplot(t(1-Nazi.temp.20[,3:15]-Nazi.temp.19[,3:15]), ylab = "", cex.axis = 0.4,
cex.lab = .8, las = 2, names = paste0("LG ",Nazi.temp.20[,1]),
horizontal = TRUE, outline = FALSE, ylim = c(0,1))

mtext(side = 1, "% judges who were appointed after 1945", line = 1.5, cex = .8)
dev.off()



##  FIGURE 6 in the SI
#pdf(file = "plots/trained_pre_33.pdf")
par(mar = c(3, 6, 1, 4))	#c(bottom, left, top, right)

boxplot(t(Nazi.temp.23[,3:15]), ylab = "", cex.axis = 0.4, cex.lab = .8, las = 2,
names = paste0("LG ",Nazi.temp.23[,1]), horizontal = TRUE, outline = FALSE, ylim = c(0,1))

mtext(side = 1, "avg. share of judges' legal training before 1933", line = 1.5, cex = .8)
dev.off()



##  FIGURE 7 in the SI
#pdf(file = "plots/trained_33_45.pdf")
par(mar = c(3, 6, 1, 4))	#c(bottom, left, top, right)

boxplot(t(Nazi.temp.24[,3:15]), ylab = "", cex.axis = 0.4, cex.lab = .8, las = 2,
names = paste0("LG ",Nazi.temp.24[,1]), horizontal = TRUE, outline = FALSE, ylim = c(0,1))

mtext(side = 1, "avg. share of judges' legal training 1933-45", line = 1.5, cex = .8)
dev.off()



##  FIGURE 8 in the SI
#pdf(file = "plots/trained_post_45.pdf")
par(mar = c(3, 6, 1, 4))	#c(bottom, left, top, right)

boxplot(t(1-Nazi.temp.23[,3:15]-Nazi.temp.24[,3:15]), ylab = "", cex.axis = 0.4,
cex.lab = .8, las = 2, names = paste0("LG ",Nazi.temp.24[,1]),
horizontal = TRUE, outline = FALSE, ylim = c(0,1))

mtext(side = 1, "avg. share of judges' legal training after 1945", line = 1.5, cex = .8)
dev.off()


sessionInfo()






.

